package main

import "container/list"

func maximumPopulation(logs [][]int) int {
	max := 0
	minYear := 0
	minStack := list.New()
	for i := 0; i < len(logs); i++ {
		for head := minStack.Front(); head != nil; {
			if head.Value.([]int)[1] < logs[i][0] {
				temp := head
				head = head.Next()
				minStack.Remove(temp)
				continue
			}

			head = head.Next()
		}
		minStack.PushBack(logs[i])

		if minStack.Len() >= max {
			max = minStack.Len()
			minYear = minStack.Front().Value.([]int)[0]
		}
	}

	return minYear
}
